package org.aceor.mddal.common.utils;

import com.google.common.base.Strings;
import org.apache.commons.collections.CollectionUtils;

import java.util.Collection;

/**
 * Created by lxue on 16/3/19.
 */
public class ValidateUtil {

    public static boolean isNullOrEmpty(Object param) {

        if (null == param) {
            return true;
        }

        if (param instanceof String) {
            return Strings.isNullOrEmpty((String)param);
        }

        if (param instanceof Collection) {
            return CollectionUtils.isEmpty((Collection) param);
        }

        return false;
    }

    /**
     * 所有都不为null或空时才返回true
     * @param params
     * @return
     */
    public static boolean isAllNotNullOrEmpty(Object... params){
        if (params == null) {
            return false;
        }
        for (Object param : params) {
            if (isNullOrEmpty(param)) {
                return false;
            }
        }
        return true;
    }
}
